/* Copyright 2012 Dustin Mitchell <dmmitche [at] gmail [dot] com>
 *
 * Licensed under the GPLv3.  See included LICENSE.txt for full details.
 */

#ifndef __ITERATOR__
#define __ITERATOR__

struct iter;

struct iter_ops
{
  void (*next)(struct iter *);
  void (*prev)(struct iter *);
  int (*compare)(struct iter *, struct iter *);
  void * (*deref)(struct iter *);
};

struct iter
{
  struct iter_ops ops;
};



/* This macro assumes the object pointed to by p has a struct iter as the first
 * object in it. */
#define ITER(p) ((struct iter *)(p))



int iter_create (struct iter *iter, struct iter_ops *ops);

void iter_next (struct iter *iter);

void iter_prev (struct iter *iter);

int iter_compare (struct iter *iter1, struct iter *iter2);

void * iter_deref (struct iter *iter);

#endif /* __ITERATOR__ */
